/**
 * 
 */
package com.xinghou.platform.dao.main.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.geo.Sphere;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.xinghou.platform.model.main.Person;
import com.xinghou.platform.util.StringUtils;

/**
 * @author wxtdy
 *
 */
@Service
public class UserGeoMONGOImpl  {/*

	@Resource
	private MongoTemplate mongoTemplate;

	*//*@Override
	public List<Person> findAll() {
		return mongoTemplate.find(new Query(), Person.class);
	}*//*

	*//*@Override
	public Person findOne(int id) {
		return mongoTemplate.findOne(new Query(Criteria.where("_id").is(id)), Person.class);
	}*//*

	*//*@Override
	public void insert(Person person) {
		mongoTemplate.insert(person);
	}*//*
	
	//.update("sex", person.getSex()).update("pos", person.getPos()).update("lastLoginTime", person.getLastLoginTime())
	*//*@Override
	public void update(Person person){
		mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(person.get_id())), 
				Update.update("cityCode", person.getCityCode()), Person.class);
	}*//*
	
	*//*public List<Person> nearSphere(Point point, Boolean sex, String orderFeild, int limit, double maxDistance) {
		//Criteria criteria = Criteria.where("pos").nearSphere(point).maxDistance(maxDistance);

		Query query = new Query();
		query.addCriteria(Criteria.where("sex").is(sex));
		query.addCriteria(Criteria.where("pos").nearSphere(point).maxDistance(maxDistance));
		return mongoTemplate.find(query.limit(limit), Person.class);
	}

*//*
	*//*public List<Person> near(Point point, Boolean sex, String orderFeild, int limit, double maxDistance) {
		Criteria criteria = Criteria.where("pos").near(point).maxDistance(maxDistance);
		Query query = new Query(criteria);
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(orderFeild != null)
			query.with(new Sort(new Sort.Order(Direction.DESC, orderFeild)));
		return mongoTemplate.find(query.limit(limit), Person.class);
	}*//*


	*//*public List<Person> withinSphere(Point center, Boolean sex, String orderFeild, int limit, double radius) {
		Sphere circle = new Sphere(center, radius);
		Criteria criteria = Criteria.where("pos").within(circle);
		Query query = new Query(criteria);
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(orderFeild != null)
			query.with(new Sort(new Sort.Order(Direction.DESC, orderFeild)));
		return mongoTemplate.find(query.limit(limit), Person.class);
	}*//*

	*//*public List<Person> within(Point center, Boolean sex, String orderFeild, int limit, double radius) {
		Sphere circle = new Sphere(center, radius);
		Criteria criteria = Criteria.where("pos").within(circle);
		Query query = new Query(criteria);
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(orderFeild != null)
			query.with(new Sort(new Sort.Order(Direction.DESC, orderFeild)));
		return mongoTemplate.find(query.limit(limit), Person.class);
	}
*//*
	*//*public List<Person> getPersonosSortById(Boolean sex, String cityCode, int limit) {
		Criteria criteria = new Criteria();
		Query query = new Query(criteria);
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(StringUtils.isNotBlank(cityCode))
			query.addCriteria(Criteria.where("cityCode").in(cityCode));
		query.with(new Sort(new Sort.Order(Direction.DESC, "_id")));
		
		return mongoTemplate.find(query.limit(limit), Person.class);
	}*//*

	*//*public List<Person> loginSortByCityCode(Boolean sex, String cityCode,
			int limit) {
		Criteria criteria = new Criteria();
		Query query = new Query(criteria);
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(StringUtils.isNotBlank(cityCode))
			query.addCriteria(Criteria.where("cityCode").in(cityCode));
		query.with(new Sort(new Sort.Order(Direction.DESC, "lastLoginTime")));
		
		return mongoTemplate.find(query.limit(limit), Person.class);
	}*//*

	*//*public List<Integer> getUserStatussSortByLoginTimeAndLocation(Boolean sex,
			String cityCode, String provinceCode, int start, int end) {
		Criteria criteria = new Criteria();
		Query query = new Query(criteria);
		query.skip(start);
		query.limit(end);
		query.fields().include("_id");
		if(sex != null)
			query.addCriteria(Criteria.where("sex").is(sex));
		if(StringUtils.isNotBlank(cityCode))
			query.addCriteria(Criteria.where("cityCode").in(cityCode));

		query.with(new Sort(new Sort.Order(Direction.DESC, "lastLoginTime")));
		
		return mongoTemplate.find(query.limit(end), Integer.class);
	}*/
}
